home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / games / uchess / src / init.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  20KB  |  812 lines

  1. /*
  2.  * init.c - C source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23. #include "gnuchess.h"
  24.  
  25. #ifdef CACHE
  26. extern struct etable __far __aligned etab[2][ETABLE];
  27. #endif
  28.  
  29. extern int __aligned ThinkInARow;
  30. extern int __aligned bookflag;
  31. extern int __aligned Sdepth2;
  32.  
  33. #ifdef AMIGA
  34. #define __USE_SYSBASE
  35. #define MOVENOWMENUNUM 0x42
  36. #define THINKMENUNUM 0x82
  37. #define SHOWMENUNUM 0xa2
  38. #define BOOKMENUNUM 0xc2
  39. #define SUPERMENUNUM 0xe2
  40. #define ADVANCEDMENUNUM 0x102
  41. #define INTERMEDIATEMENUNUM 0x122
  42. #define EASYMENUNUM 0x142
  43. #include <proto/exec.h>
  44. #include <proto/dos.h>
  45. #include <proto/intuition.h>
  46. extern int __aligned cmptr_sec,cmptr_min,hum_sec,hum_min;
  47. extern int procpri;
  48. extern struct Process *myproc;
  49. extern int __far ResignOffered;
  50. #endif
  51.  
  52. extern struct Menu Menu1;
  53. #define MenuList1 Menu1
  54. extern int MenuStripSet;
  55. extern struct MenuItem MenuItem8ab;
  56. extern struct Window __aligned *wG;
  57. unsigned int urand (void);
  58.  
  59.  
  60. /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */
  61.  
  62.  
  63. short __aligned PCRASH,PCENTER;
  64. extern int PlayMode;
  65. extern unsigned int TTadd;
  66.  
  67. #if defined NULLMOVE || defined DEEPNULL
  68. extern short int __aligned no_null;
  69. extern short int __aligned null;         /* Null-move already made or not */
  70. extern short int __aligned PVari;        /* Is this the PV */
  71. #endif
  72. extern short __aligned Threat[MAXDEPTH];
  73. extern unsigned short int __aligned PrVar[MAXDEPTH];
  74. extern short __aligned PawnStorm;
  75. extern short __aligned start_stage;
  76. extern short __aligned thrashing_tt; /* must we recycle slots at random. TomV */
  77. extern short int ISZERO;
  78. extern int __aligned global_tmp_score;
  79. extern int __aligned previous_score;
  80. int __aligned FirstTime=1;
  81. extern int SupervisorMode;
  82. extern int IllegalMove;
  83. extern int CheckIllegal;
  84. #ifdef LONGINTS2
  85. INTSIZE  __far distdata[64][64];
  86. INTSIZE  __far taxidata[64][64];
  87. #else
  88. INTSIZE  __aligned distdata[64][64];
  89. INTSIZE  __aligned taxidata[64][64];
  90. #endif
  91.  
  92. #ifdef KILLT
  93. /* put moves to the center first */
  94. void
  95. Initialize_killt (void)
  96. {
  97.   REG unsigned INTSIZE f, t, s;
  98.   REG INTSIZE d;
  99.   for (f = 64; f--;)
  100.     for (t = 64; t--;)
  101.       {
  102.     d = taxidata[f][0x1b];
  103.     if (taxidata[f][0x1c] < d)
  104.       d = taxidata[f][0x1c];
  105.     if (taxidata[f][0x23] < d)
  106.       d = taxidata[f][0x23];
  107.     if (taxidata[f][0x24] < d)
  108.       d = taxidata[f][0x24];
  109.     s = d;
  110.     d = taxidata[t][0x1b];
  111.     if (taxidata[t][0x1c] < d)
  112.       d = taxidata[t][0x1c];
  113.     if (taxidata[t][0x23] < d)
  114.       d = taxidata[t][0x23];
  115.     if (taxidata[t][0x24] < d)
  116.       d = taxidata[t][0x24];
  117.     s -= d;
  118.     killt[(f << 8) | t] = s;
  119.     killt[(f << 8) | t | 0x80] = s;
  120.       }
  121. }
  122. #endif
  123. void
  124. Initialize_dist (void)
  125. {
  126.   REG INTSIZE a, b, d, di;
  127.  
  128.   for (a = 0; a < 64; a++)
  129.     for (b = 0; b < 64; b++)
  130.       {
  131.     d = abs (column (a) - column (b));
  132.     di = abs (row (a) - row (b));
  133.     taxidata[a][b] = d + di;
  134.     distdata[a][b] = (d > di ? d : di);
  135.       }
  136. #ifdef KILLT
  137.   Initialize_killt ();
  138. #endif
  139. }
  140.  
  141. const INTSIZE __aligned Stboard[64] =
  142. {rook, knight, bishop, queen, king, bishop, knight, rook,
  143.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  144.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  145.  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  146.  pawn, pawn, pawn, pawn, pawn, pawn, pawn, pawn,
  147.  rook, knight, bishop, queen, king, bishop, knight, rook};
  148. const INTSIZE __aligned Stcolor[64] =
  149. {white, white, white, white, white, white, white, white,
  150.  white, white, white, white, white, white, white, white,
  151.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  152.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  153.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  154.  neutral, neutral, neutral, neutral, neutral, neutral, neutral, neutral,
  155.  black, black, black, black, black, black, black, black,
  156.  black, black, black, black, black, black, black, black};
  157. INTSIZE board[64], color[64];
  158.  
  159. /* given epsquare, from where can a pawn be taken? */
  160. const INTSIZE __aligned epmove1[64] =
  161. {0, 1, 2, 3, 4, 5, 6, 7,
  162.  8, 9, 10, 11, 12, 13, 14, 15,
  163.  16, 24, 25, 26, 27, 28, 29, 30,
  164.  24, 25, 26, 27, 28, 29, 30, 31,
  165.  32, 33, 34, 35, 36, 37, 38, 39,
  166.  40, 32, 33, 34, 35, 36, 37, 38,
  167.  48, 49, 50, 51, 52, 53, 54, 55,
  168.  56, 57, 58, 59, 60, 61, 62, 63};
  169. const INTSIZE __aligned epmove2[64] =
  170. {0, 1, 2, 3, 4, 5, 6, 7,
  171.  8, 9, 10, 11, 12, 13, 14, 15,
  172.  25, 26, 27, 28, 29, 30, 31, 23,
  173.  24, 25, 26, 27, 28, 29, 30, 31,
  174.  32, 33, 34, 35, 36, 37, 38, 39,
  175.  33, 34, 35, 36, 37, 38, 39, 47,
  176.  48, 49, 50, 51, 52, 53, 54, 55,
  177.  56, 57, 58, 59, 60, 61, 62, 63};
  178.  
  179.  
  180. /*
  181.  * nextpos[piece][from-square] , nextdir[piece][from-square] gives vector of
  182.  * positions reachable from from-square in ppos with piece such that the
  183.  * sequence    ppos = nextpos[piece][from-square]; pdir =
  184.  * nextdir[piece][from-square]; u = ppos[sq]; do { u = ppos[u]; if(color[u]
  185.  * != neutral) u = pdir[u]; } while (sq != u); will generate the sequence of
  186.  * all squares reachable from sq.
  187.  *
  188.  * If the path is blocked u = pdir[sq] will generate the continuation of the
  189.  * sequence in other directions.
  190.  */
  191.  
  192. unsigned char __far __aligned nextpos[8][64][64];
  193. unsigned char __far __aligned nextdir[8][64][64];
  194.  
  195. /*
  196.  * ptype is used to separate white and black pawns, like this; ptyp =
  197.  * ptype[side][piece] piece can be used directly in nextpos/nextdir when
  198.  * generating moves for pieces that are not black pawns.
  199.  */
  200. const INTSIZE __aligned ptype[2][8] =
  201. {
  202.   no_piece, pawn, knight, bishop, rook, queen, king, no_piece,
  203.   no_piece, bpawn, knight, bishop, rook, queen, king, no_piece};
  204.  
  205. /* data used to generate nextpos/nextdir */
  206. static const INTSIZE __aligned direc[8][8] =
  207. {
  208.   0, 0, 0, 0, 0, 0, 0, 0,
  209.   10, 9, 11, 0, 0, 0, 0, 0,
  210.   8, -8, 12, -12, 19, -19, 21, -21,
  211.   9, 11, -9, -11, 0, 0, 0, 0,
  212.   1, 10, -1, -10, 0, 0, 0, 0,
  213.   1, 10, -1, -10, 9, 11, -9, -11,
  214.   1, 10, -1, -10, 9, 11, -9, -11,
  215.   -10, -9, -11, 0, 0, 0, 0, 0};
  216. static const INTSIZE __aligned max_steps[8] =
  217. {0, 2, 1, 7, 7, 7, 1, 2};
  218. static const INTSIZE __aligned nunmap[120] =
  219. {
  220.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  221.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  222.   -1, 0, 1, 2, 3, 4, 5, 6, 7, -1,
  223.   -1, 8, 9, 10, 11, 12, 13, 14, 15, -1,
  224.   -1, 16, 17, 18, 19, 20, 21, 22, 23, -1,
  225.   -1, 24, 25, 26, 27, 28, 29, 30, 31, -1,
  226.   -1, 32, 33, 34, 35, 36, 37, 38, 39, -1,
  227.   -1, 40, 41, 42, 43, 44, 45, 46, 47, -1,
  228.   -1, 48, 49, 50, 51, 52, 53, 54, 55, -1,
  229.   -1, 56, 57, 58, 59, 60, 61, 62, 63, -1,
  230.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  231.   -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  232.  
  233. int __aligned InitFlag = false;
  234. void
  235. Initialize_moves (void)
  236.  
  237. /*
  238.  * This procedure pre-calculates all moves for every piece from every square.
  239.  * This data is stored in nextpos/nextdir and used later in the move
  240.  * generation routines.
  241.  */
  242.  
  243. {
  244.   INTSIZE ptyp, po, p0, d, di, s, delta;
  245.   unsigned char *ppos, *pdir;
  246.   INTSIZE dest[8][8];
  247.   INTSIZE steps[8];
  248.   INTSIZE sorted[8];
  249.  
  250.   for (ptyp = 0; ptyp < 8; ptyp++)
  251.     for (po = 0; po < 64; po++)
  252.       for (p0 = 0; p0 < 64; p0++)
  253.     {
  254.       nextpos[ptyp][po][p0] = (unsigned char) po;
  255.       nextdir[ptyp][po][p0] = (unsigned char) po;
  256.     }
  257.   for (ptyp = 1; ptyp < 8; ptyp++)
  258.     for (po = 21; po < 99; po++)
  259.       if (nunmap[po] >= 0)
  260.     {
  261.       ppos = nextpos[ptyp][nunmap[po]];
  262.       pdir = nextdir[ptyp][nunmap[po]];
  263.       /* dest is a function of direction and steps */
  264.       for (d = 0; d < 8; d++)
  265.         {
  266.           dest[d][0] = nunmap[po];
  267.           delta = direc[ptyp][d];
  268.           if (delta != 0)
  269.         {
  270.           p0 = po;
  271.           for (s = 0; s < max_steps[ptyp]; s++)
  272.             {
  273.               p0 = p0